package org.example.web;

import com.github.pagehelper.PageInfo;
import org.example.model.Attraction;
import org.example.model.Result;
import org.example.service.AttractionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController //功能是将类声明为一个控制器，并使其中的方法可以直接响应HTTP请求
@RequestMapping("/userApi/attractions")
public class AttractionController {
    @Autowired
    private AttractionService attractionService;

    @RequestMapping(path = "/info",method = RequestMethod.POST)
    public Result getAttractionInfo(@RequestBody Attraction attraction) {
        attraction.setKeywords("null".equals(attraction.getKeywords())? null : attraction.getKeywords());
        PageInfo<Attraction> pageInfo = attractionService.getAttractionInfo(attraction);
        return new Result(200, "success", pageInfo);
    }


    @RequestMapping(path = "/findById",method = RequestMethod.GET)
    public Result getAttractionById(@RequestParam("id") int id) {
        Attraction attraction = attractionService.getAttractionById(id);
        return new Result(200, "success", attraction);
    }
    @RequestMapping(path = "getDisplayImage",method = RequestMethod.GET)
    public Result getDisplayImage() {
        List<String> displayImage = attractionService.getDisplayImage();
        return new Result(200, "success", displayImage);
    }

    @RequestMapping(path = "/searchByWord",method = RequestMethod.GET)
    public Result searchByWord(@RequestParam("keyword") String keyword) {
        String url = attractionService.searchByWord(keyword);
        System.out.println(url);
        return new Result(200, "success", url);
    }




}
